package action.grant;

import service.grant.GrantService;
import util.Time;
import core.action.BaseAction;
import core.global.Global;
import model.grant.Customgrant;

public class GrantNewAction extends BaseAction{
	private Customgrant grant;
	private GrantService grantService;
	public String execute(){
		return "success";
	}
	public String grantNew(){
		Customgrant g=grantService.getGrantBycid(grant.getCustomid());
		if(g!=null){
			g.setUsedmoney(0.00);
			g.setGrantmoney(grant.getGrantmoney());
			g.setStartdate(grant.getStartdate());
			g.setEnddate(grant.getEnddate());
			g.setClerkid(Global.userid().intValue());
			g.setCreatetime(Time.CurrentTimestamp());
			g.setNote(grant.getNote());
			grantService.save_in_customgrant(g);
			if(g.getCustomtype().equals("1")){
				MessageJump("授信完成！","showGrant!findGrantListPersonal");
			}else{
				MessageJump("授信完成！","showGrant!findGrantListCompany");	
			}
		}else{
			grant.setUsedmoney(0.00);
			grant.setClerkid(Global.userid().intValue());
			grant.setCreatetime(Time.CurrentTimestamp());
			grantService.save_in_customgrant(grant);
			if(grant.getCustomtype().equals("1")){
				MessageJump("授信完成！","showGrant!findGrantListPersonal");
			}else{
				MessageJump("授信完成！","showGrant!findGrantListCompany");	
			}
		}	
		return "message";
	}
	
	
	//---------get/set---------//
	public Customgrant getGrant() {
		return grant;
	}

	public void setGrant(Customgrant grant) {
		this.grant = grant;
	}
	public GrantService getGrantService() {
		return grantService;
	}
	public void setGrantService(GrantService grantService) {
		this.grantService = grantService;
	}

}
